﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>用户维护</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <span style="margin-top:15px;margin-left:15px">
                <xblock>
                    <button class="layui-btn" onclick="saveData()"><i class="layui-icon"></i>保存</button>
                    <button class="layui-btn" onclick="closeWin()"><i class="layui-icon">&#x1006;</i>取消</button>
                </xblock>
            </span>
            <div style="margin: 20px; border: 1px solid #dbdbdb;padding:15px">
                <form class="layui-form" id="uForm">
                    <div class="layui-form-item">
                        <label class="layui-form-label">登录账号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="userCode" required lay-verify="required" autocomplete="off" class="layui-input" id="userCode" maxlength="10">
                            <input type="hidden" name="id" id="id">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="userName" required lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input" id="userName" maxlength="10">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">联系方式</label>
                        <div class="layui-input-inline">
                            <input type="text" name="userPhone" required lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input" id="userPhone">
                        </div>
                    </div>

                </form>

            </div>
    </div>
</body>
</html>
<script>
    var dataId = "";
    $(function () {
        //获取部门信息
        LoadDept("dept");
        dataId = getUrlVariable("dataId");
        if (dataId != "0") {
            $("input[ name='id']").val(dataId);
            EditUserLoad(dataId); //加载用户数据
        }
    })
    /**
    数据保存
    **/
    function saveData() {
        $.ajax({
            url: "../System/AddUser",
            data: { data: JSON.stringify(FormToJson("uForm")) },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    layer.alert("保存成功", { icon: 6 }, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }

    //加载用户数据信息
    function EditUserLoad() {

        $("#userCode").attr("readonly", "readonly");
        $.ajax({
            url: "../System/getUserInfoByCode",
            type: "post",
            data: { dataId: dataId },
            success: function (rsl) {

                if (rsl.Result) {

                    $.each(rsl.Data[0], function (name, value) {
                        if (name != "dept") {
                            $("input[ name='" + name + "']").val(value);
                        } else {
                            $("#dept option[value='" + value + "'] ").attr("selected", true);
                            layui.use('form', function () {
                                var form = layui.form;
                                form.render();
                            });
                        }
                
                    });
                 
                    if (json.isSync == 1) {
                        $("#userName").attr("readonly", "readonly");
                        $("#userPhone").attr("readonly", "readonly");
                    }
            
                }

            }
        });

    }
  

</script>

